package com.le.tester.leetcode;

/**
 * createTime：2022/8/26 13:48
 * description：detectCapitalUse，找出正确的大写字母
 */
public class DetectCapitalUse {

    public boolean detectCapitalUse(String word) {
        //first
        //1.如果第一个字符串是大写的，其余的都是小写，就证明是正确的大写字母
        if (word.equals(word.toLowerCase())) {
            return true;
        }
        String wordFirst = word.substring(0, 1);
        String wordRemain = word.substring(1);
        String wordFirstUpper = wordFirst.toUpperCase();
        String wordRemainUpper = wordRemain.toUpperCase();
        String wordRemainLower = wordRemain.toLowerCase();
        if (!wordFirst.equals(wordFirstUpper)) {
            //相等说明第一个是小写
            return false;
        }
        return wordRemain.equals(wordRemainUpper) || wordRemain.equals(wordRemainLower);
    }

    public static void main(String[] args) {

        System.out.println(new DetectCapitalUse().detectCapitalUse("Google"));
    }
}
